﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data.Sql;
using LR4.Models;

namespace LR4.DAO
{
    public class TypeDAO : DAO
    {
        public List<LR4.Models.Type> GetAllRecords()        // Метод получения всех записей из Type
        {
            Connect();
            List<LR4.Models.Type> TypeList = new List<LR4.Models.Type>();

            try
            {
                SqlCommand command = new SqlCommand("SELECT * FROM [Type]", Connection);
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    LR4.Models.Type type = new LR4.Models.Type();
                    type.ID_t = Convert.ToInt32(reader["ID_t"]);
                    type.Property_type = Convert.ToString(reader["Property_type"]);
                    TypeList.Add(type);
                }
                reader.Close();
            }

            catch (Exception)
            {
            }

            finally
            {
                Disconnect();
            }
            return TypeList;
        }

        public bool deleteType(int ID_t)               // Удаление типа недвижимости
        {
            bool result = true;
            Connect();
            try
            {
                SqlCommand cmd = new SqlCommand(
                    "DELETE FROM Type WHERE ID_t=" + ID_t, Connection);

                cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                result = false;
            }
            finally
            {
                Disconnect();
            }
            return result;
        }



    }
}
